from google.appengine.api import datastore_errors
from google.appengine.api import users
from google.appengine.ext import blobstore
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.db import Model
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp import util
from pyamf import amf3
from pyamf.remoting.gateway.google import WebAppGateway
import logging
import os
import pyamf

def echo(data):
    return 'PyAMF says: ' + data
    
def get_upload_url():
    """returns an upload url"""
    return blobstore.create_upload_url('/upload')

def main():    
    debug = True
    logging.getLogger().setLevel(logging.DEBUG)

    services = {
        'services.echo' : echo,
        'services.getUploadURL': get_upload_url,
    }

    gateway = WebAppGateway(services, logger = logging, debug = debug)

    paths = [
        ('/gateway', gateway),
    ]

    application = webapp.WSGIApplication(paths, debug = debug)
    util.run_wsgi_app(application)
    
if __name__ == '__main__':
    main()